<template>
    <h2>理财信息添加</h2>
<table class=" table-bordered" border="1">
    <tr>
        <td>理财名称</td>
        <td>
            <input type="text" v-model="Info.FinaName" placeholder="请输入理财名称">
        </td>
    </tr>
    <tr>
        <td>年收益</td>
        <td>
            <input type="text" v-model="Info.YeraMoney"  placeholder="请输入年收益">
        </td>
    </tr>
    <tr>
        <td>利息</td>
        <td>
            <select v-model="Info.LixiId">
                <option value="0">请选择</option>
                <option value="1">9</option>
                <option value="2">10</option>
                <option value="3">8</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>最低金额</td>
        <td>
            <input type="text" v-model="Info.MinMoney" placeholder="请输入最低金额">
        </td>
    </tr>
    <tr>
        <td>风险等级</td>
        <td>
            <select v-model="Info.FenId">
                <option value="0">请选择</option>
                <option value="1">一级</option>
                <option value="2">二级</option>
                <option value="3">三级</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" @click="Add" value="添加">
        </td>
    </tr>
</table>
</template>



<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter} from 'vue-router';

const router = useRouter();
const Info = ref({
    FinaId:0,
    UserId:0,
    FinaName:'',
    YeraMoney:'',
    LixiId:0,
    MinMoney:'',
    FinaNum:0,
    FenId:0
})
const Add = () => {
    //理财项目名称不能为空
    if(Info.value.FinaName == ''){
        alert("理财项目名称不能为空")
        return;
    }
    //最低金额必须大于0
    if( Number(Info.value.MinMoney) <= 0){
        alert("最低金额必须大于0")
        return;
    }
    axios.post("http://localhost:61413/api/Fina/FinaAdd",{
            FinaName:Info.value.FinaName,
            YeraMoney:Info.value.YeraMoney,
            MinMoney:Info.value.MinMoney,
            LixiId:Info.value.LixiId,
            FenId:Info.value.FenId
    })
    .then((res) => {
        if(res.data > 0){
            alert("添加成功")
            router.push("/FinaShow")
        }else if(res.data == -1){
            alert("项目名称不能重复！")
        }else{
            alert("添加失败！")
        }
    })
    .catch((err) => {
        console.log(err);
    })
}

</script>